home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / gjr / boxes.lha / squares.scm < prev   
Encoding:
Text File  |  1991-10-02  |  4.0 KB  |  129 lines

  1. ;;; -*- Scheme -*-
  2.  
  3. #|
  4.  
  5. Copyright (c) 1986-91 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case.
  34.  
  35. |#
  36.  
  37. ;;;; Henderson-Escher picture language in Scheme
  38.  
  39. (define make-rect list)
  40. (define origin car)
  41. (define horiz cadr)
  42. (define vert caddr)
  43.  
  44. (define (coord-map rect)
  45.   (lambda (point)
  46.     (+vect (+vect (scale (xcor point)(horiz rect))
  47.                   (scale (ycor point)(vert rect)))
  48.            (origin rect))))
  49.  
  50. (define make-vect cons)
  51. (define xcor car)
  52. (define ycor cdr)
  53.  
  54. (define make-segment cons)
  55. (define seg-start car)
  56. (define seg-end cdr)
  57.  
  58. (define (+vect v1 v2)
  59.   (make-vect (+ (xcor v1)(xcor v2))
  60.              (+ (ycor v1)(ycor v2))))
  61.  
  62. (define (scale a vect)
  63.   (make-vect (* a (xcor vect)) (* a (ycor vect))))
  64.  
  65. (define (make-picture seglist)
  66.   (lambda (rect)
  67.     (mapc (lambda (segment)
  68.             (drawline ((coord-map rect) (seg-start segment))
  69.                       ((coord-map rect) (seg-end segment))))
  70.           seglist)))
  71.  
  72. (define (repeated proc n)
  73.   (lambda (thing)
  74.     (if (= n 0)
  75.         thing 
  76.         ((repeated proc (-1+ n)) (proc thing)))))
  77.  
  78. (define (rotate90 pict)
  79.   (lambda (rect)
  80.     (pict (make-rect (+vect (origin rect)(horiz rect))
  81.                      (vert rect)
  82.                      (scale -1 (horiz rect))))))
  83.  
  84. (define rotate180 (repeated rotate90 2))
  85. (define rotate270 (repeated rotate90 3))
  86.  
  87. (define (flip pict)
  88.   (lambda (rect)
  89.     (pict (make-rect (+vect (origin rect) (horiz rect))
  90.                      (scale -1 (horiz rect))
  91.                      (vert rect)))))
  92.  
  93. (define (together pict1 pict2)
  94.   (lambda (rect)
  95.     (pict1 rect)
  96.     (pict2 rect)))
  97.  
  98. (define (beside  pict1 pict2 a)
  99.   (lambda (rect)
  100.     (pict1 (make-rect (origin rect)
  101.                       (scale a (horiz rect))
  102.                       (vert rect)))
  103.     (pict2 (make-rect (+vect (origin rect) (scale a (horiz rect)))
  104.                       (scale (- 1 a) (horiz rect))
  105.                       (vert rect)))))
  106.  
  107. (define (above pict1 pict2 a)
  108.   (rotate270 (beside (rotate90 pict1) (rotate90 pict2) a)))
  109.  
  110. ;; This picture is used when there is no text capability in graphics.
  111.  
  112. (define default-text-picture            ; A cross
  113.   (make-picture (list (make-segment (make-vect 0 0)
  114.                                     (make-vect 1 1))
  115.                       (make-segment (make-vect 0 1)
  116.                                     (make-vect 1 0)))))
  117.  
  118. ;;; System dependencies
  119. ;;; The names to be defined are: 
  120. ;;; screen, drawline, text-picture,
  121. ;;; clear-graphics, initialize-graphics,
  122. ;;; draw, draw-permanent.
  123.  
  124. ;; Old MIT SICP Scheme implementation is contained in chipmunk.scm
  125. ;; Old MIT CScheme implementation is contained in bobcat.scm
  126. ;; Old MacScheme implementation is contained in macscheme.scm
  127. ;; MIT CScheme 7.1 implementation (under X) contained in cscheme.scm
  128.  
  129.